import AppConfig from "../../core/config/AppConfig";
import game from "../../core/game";
import Net from "../../core/net/Net";
import Utils from "../../core/utils/Utils";
import PlayerModule from "../PlayerModule";

interface LogData {
    openid: string,
    uid: number,
    cmd: string,
    v0?: number;
    v1?: number;
    v2?: number;
    v3?: number;
    s0?: string;
    s1?: string;
    s2?: string;
    s3?: string;
}

/**打印日志 */
export class GameLog {

    private net: Net;
    private player: PlayerModule;
    private url: string;

    constructor() {
        this.net = game.get(Net);
        this.player = game.get(PlayerModule);
        this.url = AppConfig.GameLogUrl
    }

    _sendData(data: LogData) {
        if (this.url === "" || Utils.isNil(this.url)) {
            return;
        }
        if (document.location.hostname == "localhost") {
            return;
        }
        let params = {}
        for (let k in data) {
            params[k] = data[k] + ""
        }
        // this.net.(this.url, "post", params, { silent: true })
    }

    sendData(data: Omit<LogData, "openid" | "uid">) {
        (<any>data["uid"]) = this.player.uid;
        (<any>data["openid"]) = this.player.uid;

        this._sendData(<any>data);
    }

}